﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EDAC_AFS_Lib;

namespace EDAC_AFS_Converter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonDecToAfs_Click(object sender, EventArgs e)
        {
            int dec = Convert.ToInt32(textBoxAfsDec.Text);
            EDAC_TGID tgid = new EDAC_TGID(dec);

            SetInfo(tgid);
        }

        private void buttonAfsToDecimal_Click(object sender, EventArgs e)
        {
            EDAC_TGID tgid = new EDAC_TGID();
            tgid.Agency = Convert.ToInt32(textBoxAgency.Text);
            tgid.Fleet = Convert.ToInt32(textBoxFleet.Text);
            tgid.SubFleet = Convert.ToInt32(textBoxSubFleet.Text);

            SetInfo(tgid);
        }


        private void SetInfo(EDAC_TGID tgid)
        {
            labelDecAgency.Text = tgid.Agency.ToString("00");
            labelDecFleet.Text = tgid.Fleet.ToString("00");
            labelDecSubFleet.Text = tgid.SubFleet.ToString("0");
            labelDecimal.Text = tgid.TgId.ToString("000");
            labelAfsString.Text = tgid.ToString("A");
            labelAfsHexString.Text = tgid.ToString("X");
        }

        private void buttonAfsString_Click(object sender, EventArgs e)
        {
            try
            {
                EDAC_TGID tgid = new EDAC_TGID(textBoxAfsString.Text);
                SetInfo(tgid);
            }
            catch
            {
                textBoxAfsString.BackColor = Color.Red;
            }
        }

        private void textBoxAfsString_TextChanged(object sender, EventArgs e)
        {
            if (textBoxAfsString.BackColor == Color.Red) textBoxAfsString.BackColor = Color.White;
        }
    }
}
